package com.dripx;

import android.hardware.ConsumerIrManager;

/**
 * operates consumer infrared on the device.
 * Created by zhonghuanglin on 04/03/2018.
 */

public class ConsumerInfraredService extends Service {

    private ConsumerIrManager service = null;

    @Override
    String[] returnPermissionList() {
        return new String[0];
    }

    /**
     * Instances of this class must be obtained using
     * Context.getSystemService(Class) with the argument ConsumerIrManager.class
     * or Context.getSystemService(String) with the argument Context.CONSUMER_IR_SERVICE.
     */
    private ConsumerIrManager getService() {
        if (null == this.service)
            this.service = (ConsumerIrManager) context.getSystemService(this.context.CONSUMER_IR_SERVICE);
        return this.service;
    }

    /**
     * Check whether the device has an infrared emitter.
     *
     * @return boolean
     */
    public boolean isAvailable() {
        return getService().hasIrEmitter();
    }

    /**
     * Transmit an infrared pattern
     * This method is synchronous; when it returns the pattern has been transmitted.
     *
     * @param carrierFrequency int
     * @param pattern          int []
     */
    public void transmit(int carrierFrequency, int[] pattern) {
        this.getService().transmit(carrierFrequency, pattern);
    }
}
